package com.zat.mes.andrmes.dofun.todo.adapter

import android.content.Intent
import android.util.Log
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.zat.mes.andrmes.R
import com.zat.mes.andrmes.data.TodoBean
import com.zat.mes.andrmes.dofun.qualitytest.DealOnSiteHasActivity
import com.zat.mes.andrmes.dofun.qualitytest.OnSiteHasActivity
import com.zat.mes.andrmes.global.CompanionType.Companion.INTENT_EXTRA_QCID
import com.zat.mes.andrmes.global.CompanionType.Companion.INTENT_EXTRA_TASKID
import com.zat.mes.andrmes.global.CompanionType.Companion.INTENT_EXTRA_TODO
import org.json.JSONObject

/**
 * @author zy
 * @date :2020-02-22 09:28
 * @description:待办事项adapter
 */
class TodoAdapter(layoutResId: Int, empId: Long, empName: String) :
    BaseQuickAdapter<TodoBean, BaseViewHolder>(layoutResId), LoadMoreModule {

    private var empId = empId
    private var empName = empName
    override fun convert(helper: BaseViewHolder, item: TodoBean) {


        helper.setText(R.id.tvNameTodoItem, item?.todoItem)
        helper.setText(R.id.tvDateTodoItem, item?.createTime)
        var jo = JSONObject(item?.json)
        if (jo.optString("status") == "2") {
            helper.setText(R.id.tvStatusTodoItem, context.getString(R.string.text_check_pending))
        } else {
            helper.setText(
                R.id.tvStatusTodoItem,
                context.getString(R.string.text_check_pending_has)
            )
        }
        helper.itemView.setOnClickListener {
            if (context.getString(R.string.title_quality_text).equals(item?.itemType)) {

                if (jo.optString("status") == "2") {
                    try {
                        val intent = Intent(context, DealOnSiteHasActivity::class.java)
                        intent.putExtra(INTENT_EXTRA_QCID, jo.optLong("qcId"))
                        context.startActivity(intent)
                    } catch (e: Exception) {

                    }

                } else {
                    try {
                        val intent = Intent(context, OnSiteHasActivity::class.java)
                        var jo = JSONObject(item?.json)
                        intent.putExtra(INTENT_EXTRA_QCID, jo.optLong("qcId"))
                        intent.putExtra(INTENT_EXTRA_TASKID, item?.taskId)
                        intent.putExtra(INTENT_EXTRA_TODO, true)
                        context.startActivity(intent)
                    } catch (e: Exception) {
                        Log.e("activity", e.toString())
                    }

                }

            } else if (context.getString(R.string.text_check_work).equals(item?.itemType)) {

            } else if (context.getString(R.string.order).equals(item?.itemType)) {

            } else if (context.getString(R.string.produce_plan).equals(item?.itemType)) {

            }

        }
    }
}